#!/usr/local/bin/python
#   __  _                 ___       _ _                                   
#  / _\(_)_ __  _ __     / __\ __ _| | |                                               
#  \ \ | | '_ \| '_ \   / /   / _` | | |                                                
#  _\ \| | |_) | |_) | / /___| (_| | | |                                             
#  \__/|_| .__/| .__/  \____/ \__,_|_|_|                                             
#        |_|   |_|                                         
                                                        
#    ___                          _                      
#   / _ \___ _ __   ___ _ __ __ _| |_  ___  _ __         
#  / /_\/ _ \ '_ \ / _ \ '__/ _` | __|/ _ \| '__|        
# / /_\\  __/ | | |  __/ | | (_| | |_| (_) | |           
# \____/\___|_| |_|\___|_|  \__,_|\__|\___/|_|

#                    Designed for LAMS 1.0
    

# created 7th Ocotober 2008
# modified 8th October 2008
# by Carl Javier


# Note: Will deploy random calls at random intervals
# This script if run periodically may run multiple times depending the
# deploy rate
#


import os,sys,random,time

SCRIPTPATH=str(sys.path[0])+"\/"
SIPPROXY="cjavier-laptop.caia.swin.edu.au"
SIPP="/usr/local/bin/sipp"
PERL="/usr/bin/perl"
sipclients = "2000","2001","2002","2004","2005","2006","2007","2008","2009"
dialplans="dial-internal.csv","dial-local.csv","dial-interstate.csv","dial-international.csv","dial-mobile.csv"




#Generate random calls
for x in sipclients:
  #print "perl -p -i -e 's/2000/" + x +"/g' lams-sip-client"+ x+".xml"
  #os.system("perl -p -i -e 's/2000/" + x +"/g' lams-sip-client"+ x+".xml")
  #Generate random call duration in milliseconds
  callduration=str(random.randint(60000,550000))
  #Genearate random call interval in seconds
  callinterval=str(random.randint(0,500))
  #Randomly choose a dial plan to call
  randomdial=str(dialplans[random.randint(0,4)])
  
  #Deploy calls at random intervals. Calls wil be made within a 0 and 1 minutes. 
  deploydelay=random.randint(0,60)
  #print deploydelay
  time.sleep(deploydelay)
  #print randomdial with a random call interval
  os.system(SIPP+" -bg -sf "+SCRIPTPATH + "lams-sip-client"+x +".xml "+SIPPROXY +" -l 1 -inf "+SCRIPTPATH+randomdial+" -m 1 -d "+callduration)
#

#Wait awhile before executing another batch of calls or use a CRON JOB
#Will wait for at least 11 minutes as calls can take up to 9 minuts a call
#time.sleep(660)
